﻿using Bussiness.Interface;
using Bussiness.Service;
using Common;
using Common.Model;
using Model;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 
            ////Enums.UserType.Admin.GetHashCode().ToString()
            ////Enums.UserType.Admin.GetHashCode()
            ////这两个都是 3

            ////Enums.UserType.Admin.ToString() 
            ////输出  Admin

            //Console.WriteLine(Enums.UserType.Admin.GetHashCode().ToString());//3
            //Console.WriteLine(Enums.UserType.Admin.ToString());//Admin 


            //{ 
            //    Users users = new Users()
            //    {
            //        UserID = Guid.NewGuid().ToString(), Time = DateTime.Now
            //    };

            //    Books books = new Books()
            //    {
            //        BookID = Guid.NewGuid().ToString()
            //    };

            //    Orders orders = new Orders()
            //    {
            //        OrderID = Guid.NewGuid().ToString()
            //    };



            //    Orders neworders = new Orders();
            //    neworders.BookID = "";
            //    neworders.BookingStatus = "";
            //    neworders.OrderID = "";


            //    //我来过你看有这句话没
            //    //增删改查都可以这样用  具体的可以参考BaseService里面的注释
            //    IBaseService baseService = new BaseService();
            //    baseService.Insert(users);
            //    baseService.Update(users);
            //    baseService.Delete(users);

            //    //类型有方法决定   这里获取数据
            //    bool b = baseService.Insert(users).Data;

            //    //显示错误信息
            //    string s = baseService.Insert(users).Msg;

            //    //操作是否成功   bool类型
            //    bool c = baseService.Insert(users).Success;

            //    //将错误信息输出控制台
            //    Console.WriteLine(s);

            //    //as
            //    //特踏实testsssss 阿三
            //    ///test2
            //    ///test3
            //    ///

            //    //baseService.Select()
            //}
            #endregion
            {
                Enums.UserType[] usertype = new Enums.UserType[6]{
                    Enums.UserType.User,
                    Enums.UserType.VIP,
                    Enums.UserType.Emp,
                    Enums.UserType.Admin,
                    Enums.UserType.User,
                    Enums.UserType.User
                };
                IBaseService baseService = new BaseService();
                for (int i = 0; i <= 4; i++)
                {
                    for (int t = 0; t < 4; t++)
                    {
                        Users users = new Users()
                        {
                            UserID = Guid.NewGuid().ToString(),//用户ID
                            UserName = $"test{(i + t).ToString()}",//姓名testi+t
                            Name = $"testname{(i + t).ToString()}",
                            Address = $"ttttt{(i + t).ToString()}",
                            UserType = usertype[i].ToString(),
                            Password = MD5Encrypt.Encrypt((i + t).ToString()),
                            Time = DateTime.Now.AddMinutes((i + t))
                        };
                        Books books = new Books()
                        {
                            BookID = Guid.NewGuid().ToString(),
                            BookName = $"testBookName{(i + t).ToString() }",
                            Author = $"testAuthor{(i + t).ToString()}",
                            Publishing = $"testPublishing{(i + t).ToString()}",
                            Num = (i + t),
                            Price = (i + t),
                            BookType = $"王牌{(i + t).ToString()}",
                            StockTime = DateTime.Now.AddMinutes((i + t)),
                            Remake = $"testRemake{(i + t).ToString()}"
                        };

                        Orders orders = new Orders()
                        {
                            OrderID = Guid.NewGuid().ToString(),
                            BookID = books.BookID,
                            UserID = users.UserID,
                            Num = (i + t),
                            Price = (i + t) * books.Price,
                            CopUser = users.Name,
                            BookingTime = DateTime.Now.AddMinutes((i + t)),
                            BookingStatus = Enums.BookingStatus.JoinCar.ToString()
                        };


                        Result<bool> boolusers = baseService.Insert(users);
                        Result<bool> boolbooks = baseService.Insert(books);
                        Result<bool> boolorders = baseService.Insert(orders);
                        bool result = boolusers.Data && boolbooks.Data && boolorders.Data;
                        if (result)
                        {
                            Console.WriteLine("success");
                        }
                        else
                        {
                            Console.WriteLine(boolusers.Msg);
                            Console.WriteLine(boolbooks.Msg);
                            Console.WriteLine(boolorders.Msg);
                        }
                    }
                }

                //我来过你看有这句话没
                //增删改查都可以这样用  具体的可以参考BaseService里面的注释
                string password = MD5Encrypt.Encrypt("0");
                Result<List<Users>> listresult = baseService.Select<Users>(p => p.UserName == "test0", c => c.Password == password);
                if (listresult.Data.Count > 0)
                {
                    Console.WriteLine("存在");
                }
            }
            //MD5加密
            MD5Encrypt.Encrypt("asdasd");
            Console.ReadKey();
            Console.ReadKey();
        }
    }
}
